﻿


#if record类测试
TestRecordClass testRecord1 = new TestRecordClass("A", 15);
TestRecordClass testRecord2 = new TestRecordClass("B", 13);
Console.WriteLine(testRecord1.ToString());
Console.WriteLine(testRecord2.ToString()); 

//TestRecordClass2 test2 = new TestRecordClass2("A", 15);
//test2.NickName = "A";

TestRecordClass2 test2 = new TestRecordClass2("A", 15, "B");
Console.WriteLine(test2.ToString());

TestRecordClass2 test3 = test2 with { };
//TestRecordClass2 test3 = test2 with { name = "VVV" };//创建了test2的副本，不是用一个对象，内容完全一样。也可以在创建副本中修改对应的值
Console.WriteLine(test3.ToString());
Console.WriteLine(test3 == test2);//true
Console.WriteLine(Object.ReferenceEquals(test2, test3));//false
#endif



using (HuAdminContext context = new HuAdminContext())
{
    Console.WriteLine("请输入：");
    var name = Console.ReadLine();
    var model = context.HuUsers.Single(u => u.Id == "46a259d4edcf4eb1b531fb58b4156d5c");

    Thread.Sleep(5000);
    if (!string.IsNullOrWhiteSpace(model.RealName))
    {
        Console.WriteLine("已被占用.....");
        Console.ReadLine();
        return;
    }
    model.RealName = name;

    //context.HuUsers.Add(new Hu.Domain.Model.HuUser
    //{
    //    Email = "163.com",
    //    Password = "123",
    //    RealName = "胡胡03",
    //    UserName = "huhu02"
    //});
    try
    {
        await context.SaveChangesAsync();
    }
    catch (DbUpdateConcurrencyException ex)
    {
        var entry = ex.Entries.Single();
        var databaseValues = entry.GetDatabaseValues(); // 当前数据库中的值
        var clientValues = entry.Entity;               // 当前客户端尝试提交的值
        Console.WriteLine($"已被{databaseValues.GetValue<string>("RealName")}占用{clientValues}.....");
        Console.ReadLine();
        return;
    }
    //foreach (var user in context.HuUsers)
    //{
    //    Console.WriteLine(user.RealName);
    //}
}

Console.WriteLine("Press any key to exit...");
Console.ReadKey();
